package cn.kk.exception;

import cn.kk.base.exception.BaseExceptionAdvice;
import cn.kk.base.model.Result;
import cn.kk.utils.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: kk
 * @Date: 2023/3/5  19:09
 * @Version 1.0
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionAdvice extends BaseExceptionAdvice {
    /**
     * 业务异常
     * @param e 异常
     * @return 错误信息
     */
    @ExceptionHandler(ExceptionUtil.BizException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public Result<Object> bizExceptionHandler(ExceptionUtil.BizException e) {
        log.error("[业务异常]" + e.getMessage(), e);
        return Result.error(e.getErrorCodeEnum());
    }
}
